#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QtGui/QGridLayout>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    m_window = new MapWindow(this);

    m_window->resize(640, 480);
    m_window->move(0, 20);


    m_window->show();

    connect(ui->actionLoad, SIGNAL(triggered()), this, SLOT(Load()));
    connect(ui->actionNew, SIGNAL(triggered()), this, SLOT(New()));
    connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(Save()));
    connect(ui->actionLoad_2, SIGNAL(triggered()), this, SLOT(LoadTile()));
    connect(ui->actionLayer_4, SIGNAL(triggered()), this, SLOT(SetActiveLayer1()));
    connect(ui->actionLayer_5, SIGNAL(triggered()), this, SLOT(SetActiveLayer2()));
    connect(ui->actionLayer_6, SIGNAL(triggered()), this, SLOT(SetActiveLayer3()));
    connect(ui->actionLayer_7, SIGNAL(triggered()), this, SLOT(SetActiveLayer4()));
    connect(ui->checkBox, SIGNAL(toggled(bool)), this, SLOT(Check1(bool)));
    connect(ui->checkBox_2, SIGNAL(toggled(bool)), this, SLOT(Check2(bool)));
    connect(ui->checkBox_3, SIGNAL(toggled(bool)), this, SLOT(Check3(bool)));
    connect(ui->checkBox_4, SIGNAL(toggled(bool)), this, SLOT(Check4(bool)));

    connect(ui->actionSave_2, SIGNAL(triggered()), this, SLOT(SaveDS()));


}

MainWindow::~MainWindow()
{
    delete ui;
    if(m_window) delete m_window;
}
void MainWindow::LoadTile()
{
    QString f = QFileDialog::getOpenFileName(this, "Load a TileSheet");

    m_window->LoadTile(f.toStdString());
}

void MainWindow::Save()
{
    m_window->Save();
}

void MainWindow::Load()
{
    m_window->Load();
}

void MainWindow::New()
{
    m_window->New();
}

void MainWindow::Check1(bool checked)
{
    m_window->ShowLayer(0, checked);
}


void MainWindow::Check2(bool checked)
{
    m_window->ShowLayer(1, checked);
}

void MainWindow::Check3(bool checked)
{
    m_window->ShowLayer(2, checked);
}

void MainWindow::Check4(bool checked)
{
    m_window->ShowLayer(3, checked);
}
void MainWindow::SetActiveLayer1()
{
    m_window->SetCurrentLayer(0);
}

void MainWindow::SetActiveLayer2()
{
    m_window->SetCurrentLayer(1);
}

void MainWindow::SetActiveLayer3()
{
    m_window->SetCurrentLayer(2);
}

void MainWindow::SetActiveLayer4()
{
    m_window->SetCurrentLayer(3);
}
